<?php

namespace App\Filament\Resources;

use App\Filament\Resources\NavigationResource\Pages;
use App\Models\Navigation;
use Filament\Forms\Components\Radio;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Form;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Table;

class NavigationResource extends Resource
{
    protected static ?string $model = Navigation::class;

    protected static ?string $navigationIcon = 'heroicon-o-paper-airplane';

    protected static ?int $navigationSort = 1;

    // 导航项分组翻译
    public static function getNavigationGroup(): ?string
    {
        return __('menu.website_group.name');
    }

    // 菜单标题导航翻译
    public static function getNavigationLabel(): string
    {
        return __('menu.website_group.navigation');
    }

    // 面包屑导航翻译
    public static function getModelLabel(): string
    {
        return __('menu.website_group.navigation');
    }

    public static function form(Form $form): Form
    {
        return $form
            ->schema([
                TextInput::make('name')
                    ->label(__('navigation.Name')),
                TextInput::make('route')
                    ->label(__('navigation.Route'))
                    ->suffixIcon('heroicon-m-globe-alt'),
                TextInput::make('sort')
                    ->label(__('navigation.Sort'))
                    ->integer(),
                Radio::make('status')
                    ->label(__('navigation.Status'))
                    ->options([
                        '0' => __('navigation.Status_0'),
                        '1' => __('navigation.Status_1'),
                    ])
                    ->inline()
                    ->inlineLabel(false)
                    ->default('1')
                    ->required(),
            ])
            ->columns(1);
    }

    public static function table(Table $table): Table
    {
        return $table
            ->columns([
                TextColumn::make('name')
                    ->label(__('navigation.Name'))
                    ->badge()
                    ->alignCenter(),
                TextColumn::make('route')
                    ->label(__('navigation.Route'))
                    ->icon('heroicon-m-globe-alt')
                    ->copyable(),
                TextColumn::make('sort')->label(__('navigation.Sort'))->alignCenter(),
                TextColumn::make('status')
                    ->label(__('navigation.Status'))
                    ->badge()
                    ->color(fn (string $state): string => match ($state) {
                        '0' => 'gray',
                        '1' => 'success',
                    })
                    ->formatStateUsing(fn (string $state): string => match ($state) {
                        '0' => __('navigation.Status_0'),
                        '1' => __('navigation.Status_1'),
                    })
                    ->alignCenter(),
            ])
            ->filters([
                //
            ])
            ->actions([
                Tables\Actions\EditAction::make(),
            ])
            ->bulkActions([
                Tables\Actions\BulkActionGroup::make([
                    Tables\Actions\DeleteBulkAction::make(),
                ]),
            ])
            ->defaultSort('sort')
            ->reorderable('sort');
    }

    public static function getRelations(): array
    {
        return [
            //
        ];
    }

    public static function getPages(): array
    {
        return [
            'index' => Pages\ListNavigations::route('/'),
        ];
    }
}
